﻿using System;
using YKXiangQi.Common;
using YKXiangQi.Enums;

namespace YKXiangQi.Models
{
    [Serializable]
    public abstract class Piece
    {
        public abstract string Name { get; }
        
        public abstract int PieceMaskValue { get; }
        //_2^4_ _2^3_ _2^2_ _2^1_ _2^0_
        //|  A  |  P  |  E  |  K  |R,C,H|
        //|_____|_____|_____|_____|_____|

        public Sides Side { get; set; }

        public abstract string Notation { get;}

        public abstract string LocalNotation { get; }

        public static Piece FromString(string pieceName)
        {
            Piece piece = null;
            switch (pieceName.ToLower())
            {
                case "r":
                    {
                        piece = new Rook();
                        break;
                    }
                case "h":
                case "n":
                    {
                        piece = new Horse();
                        break;
                    }
                case "e":
                case "b":
                    {
                        piece = new Elephant();
                        break;
                    }
                case "a":
                    {
                        piece = new Advisor();
                        break;
                    }
                case "k":
                    {
                        piece = new King();
                        break;
                    }
                case "c":
                    {
                        piece = new Cannon();
                        break;
                    }
                case "p":
                    {
                        piece = new Pawn();
                        break;
                    }
            }

            if (piece != null)
            {
                if (pieceName.IsLowerCase())
                    piece.Side = Sides.Black;
                else
                    piece.Side = Sides.Red;
            }

            return piece;
        }

        public ViewMode ViewMode { get; set; }
    }
}